package gui;
/**
 * @author Shun Fan
 * 
 */
import gui.properties.groups.AbstractGroup;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import model.Model;

public class Prompt extends JPanel
{
	private JTextField textfield;
	private JComboBox comboBox;
	private JTextArea textarea; 
	private ArrayList<String> previousCommands;
	
	private Model myModel;
	
	public Prompt(Model model) 
	{
		myModel = model;
		this.add( createComboLine(), BorderLayout.NORTH);
		this.add( createPrompt(), BorderLayout.SOUTH);
	}
		
	private JPanel createPrompt()
	{
		JPanel panel = new JPanel();
		textarea = new JTextArea();
		textarea.setPreferredSize(new Dimension(800, 100));
		textarea.setLineWrap(true);
		textarea.setWrapStyleWord(true);
		textarea.setEditable(false);
		textarea.setBackground(Color.gray);
		
		panel.setBorder(BorderFactory.createTitledBorder("Prompt"));
		panel.add(new JScrollPane(textarea));
		return panel;
	}
		
	private JPanel createComboLine() {
		JPanel panel = new JPanel();
		panel.add(new JLabel("Command Line:"));
		comboBox = new JComboBox();
		comboBox.setPreferredSize(new Dimension(400, 30));
		comboBox.setEditable(true);
		
		JButton button = new JButton("Execute");
		button.addActionListener(
			new ActionListener() {					 
	            public void actionPerformed(ActionEvent e)
	            {
	            	String line = (String) comboBox.getSelectedItem();
	            	myModel.runInput(line);
	            	comboBox.insertItemAt(line, 0);
	            }
			}
		);
		
		panel.add(comboBox);
		panel.add(button);
		return panel;
	}
	
	public class ExecuteLine implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			String toSend = textfield.getText();
			textfield.setText("");
			//send to model
		} 
	
	}
	

	public void displayError(String error) {
		textarea.setText(error);
	}
	
	public static void main(String args[]) throws IOException {
		JFrame f = new JFrame();
		Model m = new Model();
		f.setSize(1000, 1000);
		Prompt p = new Prompt(m);
		f.add(p);
		f.setVisible(true);
	}
}
